package com.t9;

/**
 * Created by xuyiwei on 2018/7/21.
 */
interface Service{ void method1(); void method2();}
interface ServiceFactory{Service getService();}
class Imple1 implements Service{
    @Override
    public void method1() {System.out.println("Imple1 method1()");}
    @Override
    public void method2() {System.out.println("Imple1 method2()");}
}
class Imple1Factory implements ServiceFactory{
    @Override
    public Service getService() {return new Imple1();}
}
class Imple2 implements Service{
    @Override
    public void method1() { System.out.println("Imple2 method1()");}
    @Override
    public void method2() {System.out.println("Imple2 method2()");}
}
class Imple2Factory implements ServiceFactory{
    @Override
    public Service getService() {return new Imple2();}
}
public class Factories {
    public static void sereviceConsumer(ServiceFactory fact){
        Service s = fact.getService(); s.method1(); s.method2();
    }
    public static void main(String[] args) {
        sereviceConsumer(new Imple1Factory());
        sereviceConsumer(new Imple2Factory());
        /**
         * Imple1 method1()
         Imple1 method2()
         Imple2 method1()
         Imple2 method2()
         */
    }
}
